﻿// Decompiled with JetBrains decompiler
// Type: UnityEngine.RectOffset
// Assembly: UnityEngine.CoreModule, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
// MVID: E6AE6B5A-2752-4B07-9528-C8B77C62CE79
// Assembly location: C:\Users\windys\Unity\2021.3.39f1c1\Editor\Data\Managed\UnityEngine\UnityEngine.CoreModule.dll
// XML documentation location: C:\Users\windys\Unity\2021.3.39f1c1\Editor\Data\Managed\UnityEngine\UnityEngine.CoreModule.xml

using System;
using System.Globalization;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using UnityEngine.Bindings;
using UnityEngine.Scripting;

#nullable disable
namespace UnityEngine
{
  /// <summary>
  ///   <para>Offsets for rectangles, borders, etc.</para>
  /// </summary>
  [UsedByNativeCode]
  [NativeHeader("Modules/IMGUI/GUIStyle.h")]
  [Serializable]
  [StructLayout(LayoutKind.Sequential)]
  public class RectOffset : IFormattable
  {
    [VisibleToOtherModules(new string[] {"UnityEngine.IMGUIModule"})]
    [NonSerialized]
    internal IntPtr m_Ptr;
    private readonly object m_SourceStyle;

    /// <summary>
    ///   <para>Creates a new rectangle with offsets.</para>
    /// </summary>
    /// <param name="left"></param>
    /// <param name="right"></param>
    /// <param name="top"></param>
    /// <param name="bottom"></param>
    public RectOffset() => this.m_Ptr = RectOffset.InternalCreate();

    [VisibleToOtherModules(new string[] {"UnityEngine.IMGUIModule"})]
    internal RectOffset(object sourceStyle, IntPtr source)
    {
      this.m_SourceStyle = sourceStyle;
      this.m_Ptr = source;
    }

    ~RectOffset()
    {
      if (this.m_SourceStyle != null)
        return;
      this.Destroy();
    }

    /// <summary>
    ///   <para>Creates a new rectangle with offsets.</para>
    /// </summary>
    /// <param name="left"></param>
    /// <param name="right"></param>
    /// <param name="top"></param>
    /// <param name="bottom"></param>
    public RectOffset(int left, int right, int top, int bottom)
    {
      this.m_Ptr = RectOffset.InternalCreate();
      this.left = left;
      this.right = right;
      this.top = top;
      this.bottom = bottom;
    }

    /// <summary>
    ///   <para>Returns a formatted string for this RectOffset.</para>
    /// </summary>
    /// <param name="format">A numeric format string.</param>
    /// <param name="formatProvider">An object that specifies culture-specific formatting.</param>
    public override string ToString() => this.ToString((string) null, (IFormatProvider) null);

    /// <summary>
    ///   <para>Returns a formatted string for this RectOffset.</para>
    /// </summary>
    /// <param name="format">A numeric format string.</param>
    /// <param name="formatProvider">An object that specifies culture-specific formatting.</param>
    public string ToString(string format) => this.ToString(format, (IFormatProvider) null);

    /// <summary>
    ///   <para>Returns a formatted string for this RectOffset.</para>
    /// </summary>
    /// <param name="format">A numeric format string.</param>
    /// <param name="formatProvider">An object that specifies culture-specific formatting.</param>
    public string ToString(string format, IFormatProvider formatProvider)
    {
      if (formatProvider == null)
        formatProvider = (IFormatProvider) CultureInfo.InvariantCulture.NumberFormat;
      return UnityString.Format("RectOffset (l:{0} r:{1} t:{2} b:{3})", (object) this.left.ToString(format, formatProvider), (object) this.right.ToString(format, formatProvider), (object) this.top.ToString(format, formatProvider), (object) this.bottom.ToString(format, formatProvider));
    }

    private void Destroy()
    {
      if (!(this.m_Ptr != IntPtr.Zero))
        return;
      RectOffset.InternalDestroy(this.m_Ptr);
      this.m_Ptr = IntPtr.Zero;
    }

    [ThreadAndSerializationSafe]
    [MethodImpl(MethodImplOptions.InternalCall)]
    private static extern IntPtr InternalCreate();

    [ThreadAndSerializationSafe]
    [MethodImpl(MethodImplOptions.InternalCall)]
    private static extern void InternalDestroy(IntPtr ptr);

    /// <summary>
    ///   <para>Left edge size.</para>
    /// </summary>
    [NativeProperty("left", false, TargetType.Field)]
    public extern int left { [MethodImpl(MethodImplOptions.InternalCall)] get; [MethodImpl(MethodImplOptions.InternalCall)] set; }

    /// <summary>
    ///   <para>Right edge size.</para>
    /// </summary>
    [NativeProperty("right", false, TargetType.Field)]
    public extern int right { [MethodImpl(MethodImplOptions.InternalCall)] get; [MethodImpl(MethodImplOptions.InternalCall)] set; }

    /// <summary>
    ///   <para>Top edge size.</para>
    /// </summary>
    [NativeProperty("top", false, TargetType.Field)]
    public extern int top { [MethodImpl(MethodImplOptions.InternalCall)] get; [MethodImpl(MethodImplOptions.InternalCall)] set; }

    /// <summary>
    ///   <para>Bottom edge size.</para>
    /// </summary>
    [NativeProperty("bottom", false, TargetType.Field)]
    public extern int bottom { [MethodImpl(MethodImplOptions.InternalCall)] get; [MethodImpl(MethodImplOptions.InternalCall)] set; }

    /// <summary>
    ///   <para>Shortcut for left + right. (Read Only)</para>
    /// </summary>
    public extern int horizontal { [MethodImpl(MethodImplOptions.InternalCall)] get; }

    /// <summary>
    ///   <para>Shortcut for top + bottom. (Read Only)</para>
    /// </summary>
    public extern int vertical { [MethodImpl(MethodImplOptions.InternalCall)] get; }

    /// <summary>
    ///   <para>Add the border offsets to a rect.</para>
    /// </summary>
    /// <param name="rect"></param>
    public Rect Add(Rect rect)
    {
      Rect ret;
      this.Add_Injected(ref rect, out ret);
      return ret;
    }

    /// <summary>
    ///   <para>Remove the border offsets from a rect.</para>
    /// </summary>
    /// <param name="rect"></param>
    public Rect Remove(Rect rect)
    {
      Rect ret;
      this.Remove_Injected(ref rect, out ret);
      return ret;
    }

    [MethodImpl(MethodImplOptions.InternalCall)]
    private extern void Add_Injected(ref Rect rect, out Rect ret);

    [MethodImpl(MethodImplOptions.InternalCall)]
    private extern void Remove_Injected(ref Rect rect, out Rect ret);
  }
}
